import type { LedgerRecycleItem } from '#/views/system/ledger-recycle/data';

import { requestClient } from '#/api/request';

export namespace LedgerRecycleApi {
  export interface LedgerRecycleListParams {
    keyword?: string;
    page: number;
    pageSize: number;
  }

  export interface LedgerRecycleListResult {
    list: LedgerRecycleItem[];
    page: number;
    pageSize: number;
    total: number;
  }
}

/**
 * 获取账簿回收站列表
 */
export async function getLedgerRecycleList(
  params: LedgerRecycleApi.LedgerRecycleListParams,
): Promise<LedgerRecycleApi.LedgerRecycleListResult> {
  const response = await requestClient.get<{
    list: LedgerRecycleItem[];
    page: number;
    pageSize: number;
    total: number;
  }>('/system/ledger-recycle/list', { params });

  return {
    list: response.list || [],
    page: response.page || 1,
    pageSize: response.pageSize || 20,
    total: response.total || 0,
  };
}

/**
 * 恢复账簿
 */
export async function restoreLedger(id: string): Promise<void> {
  await requestClient.post(`/system/ledger-recycle/${id}/restore`);
}

/**
 * 彻底删除账簿
 */
export async function permanentDeleteLedger(id: string): Promise<void> {
  await requestClient.delete(`/system/ledger-recycle/${id}`);
}